﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Zor_IDAL;
using Zor_Modes;

namespace Zor_DAL
{
    public class News_DAL<T> where T : class
    {

        /// <summary>
        /// 获取新闻列表
        /// </summary>
        /// <returns></returns>
        public static List<T> GetNewList()
        {
            var sql = "select * from NewInfo";
            List<T> lst = DapperQuery<T>.DoQueryList(sql, null);
            return lst;
        }

        /// <summary>
        /// 获取新闻根据ID
        /// </summary>
        /// <param name="id">新闻ID</param>
        /// <returns></returns>
        public static T GetNewById(int id)
        {
            var sql = "select * from NewInfo where New_Id = @New_Id";
            return DapperQuery<T>.DoQueryT(sql, new { New_Id = id });
        }


        /// <summary>
        /// 新增新闻
        /// </summary>
        /// <returns></returns>
        public static BaseAnswer InsertNews(NewInfo news)
        {
            BaseAnswer ba = new BaseAnswer();
            var sql = "insert into NewInfo values(@New_Title,@New_Info,@New_CreateDate,@New_CreateUser)";
            ba = DapperInsert<T>.DoInsert(sql, news);
            return ba;
        }

        /// <summary>
        /// 编辑新闻
        /// </summary>
        /// <param name="news">新闻</param>
        /// <returns></returns>
        public static BaseAnswer UpdateNews(NewInfo news)
        {
            var sql = "update NewInfo set New_Title=@New_Title,New_Info=@New_Info,New_CreateDate=@New_CreateDate,New_CreateUser=@New_CreateUser where New_Id = @New_Id";
            BaseAnswer bar = DapperEdit<T>.DoEdit(sql, news);
            return bar;
        }

        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static BaseAnswer DeleteNews(int[] ids)
        {

            var sql = "delete from NewInfo where New_Id in @New_Id";
            BaseAnswer bar = DapperDelete<T>.DoDelete(sql, new { New_Id =ids});
            return bar;
        }

    }
}
